package main

import (
	"fmt"
	"io"
	"net/http"
)

func main() {
	// 注册路由 router
	// xxxx/user   	----> func1
	// xxxx/home   	----> func2
	// xxxx/product ----> func3
	http.HandleFunc("/api/user", func(writer http.ResponseWriter, request *http.Request) {
		// writer：服务器写回给客户端
		fmt.Println("用户请求详情：")
		fmt.Println("request:", request)
		// request：客户端发来的请求
		io.WriteString(writer, "这是/api/user请求")
	})

	http.HandleFunc("/api/home", func(writer http.ResponseWriter, request *http.Request) {
		io.WriteString(writer, "这是/api/home")
	})

	http.HandleFunc("/api/product", func(writer http.ResponseWriter, request *http.Request) {
		io.WriteString(writer, "这是/api/product")
	})

	err := http.ListenAndServe(":9000", nil)
	if err != nil {
		panic(err)
	}
}
